<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <!-- 是因为我们在切换元素的时候，vue默认会复用原先的元素，提供性能 -->
      <!-- 可以给元素添加唯一的key属性，就不会再复用 -->
      <!-- key只能加基本类型的数据，加数字或者字符串 -->
      <template v-if="loginType === 'username'">
        <label>Username</label>
        <input placeholder="Enter your username" key="1" />
      </template>
      <template v-else>
        <label>Email</label>
        <input placeholder="Enter your email address" key="2" />
      </template>

      <hr />

      <button @click="fn">btn</button>
    </div>

    <script src="../Vue.js"></script>
    <script>
      new Vue({
        el: "#app",
        data: {
          loginType: "username",
        },
        methods: {
          fn() {
            this.loginType =
              this.loginType === "username" ? "email" : "username";
          },
        },
      });
    </script>
  </body>
</html>
